home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / msgq160s.arc / SETTINGS.C < prev    next >
Text File  |  1991-10-26  |  12KB  |  424 lines

  1. /*
  2.  * SETTINGS.C - Settings screen
  3.  *
  4.  * Msged/Q message editor for QuickBBS  Copyright 1990 by P.J. Muller
  5.  *
  6.  */
  7.  
  8. #include <stdlib.h>        /* must be here for min/max */
  9.  
  10. #include "msged.h"
  11. #include "qmsgbase.h"
  12.  
  13. #ifdef SETTINGS
  14.  
  15. #include "screen.h"
  16. #include <string.h>        /* include here for compile speed */
  17. #include <stdio.h>
  18. #include <ctype.h>
  19.  
  20. #define TLEN    64
  21. #define ILEN    40
  22. #define ORGOFS    15
  23.  
  24. #define FFIRST  1
  25. #define FLAST   18
  26.  
  27. #define SWBEGIN  9
  28. #define SWEND    18
  29.  
  30. #define SBEGIN  1
  31. #define SEND    6
  32.  
  33. #define NBEGIN  7
  34. #define NEND    8
  35.  
  36. #define SWLINE  15
  37. #define STLINE  5
  38. #define NULINE  11
  39. #define PILINE  1
  40.  
  41. #define OFFSET 35
  42.  
  43. static void update(int f);
  44. static BOOLEAN checkname(char *n);
  45.  
  46. static  char    taddr[TLEN];
  47.  
  48. static  char   *tname,
  49.                *tlist1,
  50.                *tlist2,
  51.                *tqs,
  52.                *torg;
  53.  
  54. static  int     trm,
  55.         tusernum,
  56.                 ttab;
  57.  
  58. static  int     tcr,
  59. #ifdef SEENBY
  60.         tseen,
  61. #endif
  62. #ifdef TEARLINE
  63.         ttear,
  64. #endif
  65.                 tconfirm,
  66.         tbeep,
  67.                 tshow,
  68.         tsrch,
  69.                 tpriv,
  70.                 tcrash,
  71.                 tkill;
  72.  
  73. void settings()
  74. {
  75.   int f = 1;
  76.   int ch = 0;
  77.   char tmp[TLEN];
  78.  
  79.   /* first close the message base */
  80.   if (!closemsgbase())
  81.     fatal("Could not close message base");
  82.  
  83.   /* temporary variables until <enter> is pressed */
  84.  
  85.   tname = strdup(username);
  86.   tqs = strdup(quotestr);
  87.  
  88.   memset(tmp,0,sizeof(tmp));
  89.  
  90. /* Removed: read origin line for current area into 'tmp', else */
  91.  
  92.   if (origin != NULL)
  93.     strcpy(tmp,origin);
  94.   else
  95.     strcpy(tmp,username);
  96.  
  97.   torg = strdup(tmp);
  98.  
  99.   trm = rm;
  100.   tusernum = usernum;
  101.   ttab = tabsize;
  102.  
  103. #ifdef SEENBY
  104.   tseen = seenbys;
  105. #endif
  106. #ifdef TEARLINE
  107.   ttear = tearline;
  108. #endif
  109.   tcr = arealist[area].softcr;
  110.   tconfirm = confirmations;
  111.   tbeep = beepson;
  112.   tshow = shownotes;
  113.   tpriv = arealist[area].msgbits.is_priv;
  114.   tcrash = arealist[area].msgbits.is_crash;
  115.   tkill = arealist[area].msgbits.is_kill;
  116.   tsrch = globsrch;
  117.  
  118.   if (userlist != NULL)
  119.     tlist2 = strdup(userlist);
  120.   else
  121.     tlist2 = strdup(" ");
  122.  
  123.   if (fidolist != NULL)
  124.     tlist1 = strdup(fidolist);
  125.   else
  126.     tlist1 = strdup(" ");
  127.  
  128.   strcpy(taddr,formaddr(thisnode[CurAKA],Z_A|N_A|P_O|D_O));
  129.  
  130.   set_color(co_info);
  131.  
  132.   cls();
  133.   gotoxy(1,PILINE);  bputs("Msged/Q " VERSION " settings");
  134.   gotoxy(1,STLINE); bputs("String Settings");
  135.   gotoxy(1,NULINE); bputs("Numeric Settings");
  136.   gotoxy(1,SWLINE); bputs("Switches");
  137.   gotoxy(16,SWLINE);  bprintf("Current area %s (%s)", arealist[area].tag,
  138.             arealist[area].description);
  139.   for (f = FFIRST; f <= FLAST; f++)
  140.     update(f);
  141.  
  142.   f = 1;
  143.   gotoxy(1,22);
  144.   bputs("________________________________________________________________________________");
  145.   gotoxy(10,23); bputs("Use the arrow keys to select a setting or switch.  Esc to abort.");
  146.   gotoxy(10,24); bputs("Press the <spacebar> to change a setting or toggle a switch.");
  147.   gotoxy(10,25); bputs("Use the normal editing keys to change string and numeric settings.");
  148.  
  149.   while (ch != ABORT) {
  150.  
  151.     set_color(co_hilite);
  152.     update(f);
  153.     set_color(co_info);
  154.  
  155.     gotoxy(1,maxy);
  156.     video_update();
  157.  
  158.     ch = getkey();
  159.  
  160.     if (ch != SPACE)
  161.       update(f);
  162.  
  163.     switch (ch) {
  164.       case UP:
  165.     if (f > FFIRST)
  166.       f--;
  167.     else
  168.       f = FLAST;
  169.     if ((f > SWBEGIN) && (f <= SWEND))
  170.       f--;
  171. #ifndef TEARLINE
  172.     if (f == 10) f--;
  173. #endif
  174. #ifndef SEENBY
  175.     if (f == 9) f--;
  176. #endif
  177.     break;
  178.  
  179.       case DOWN:
  180.     if (f < FLAST)
  181.       f++;
  182.     else
  183.       f = FFIRST;
  184.     if ((f < SWEND) && (f > SWBEGIN))
  185.       f++;
  186. #ifndef SEENBY
  187.     if (f == 9) f++;
  188. #endif
  189. #ifndef TEARLINE
  190.     if (f == 10) f++;
  191. #endif
  192.     break;
  193.  
  194.       case LEFT:
  195.     if (f > FFIRST)
  196.       f--;
  197.     else
  198.       f = FLAST;
  199. #ifndef TEARLINE
  200.     if (f == 10) f--;
  201. #endif
  202. #ifndef SEENBY
  203.     if (f == 9) f--;
  204. #endif
  205.     break;
  206.  
  207.       case RIGHT:
  208.     if (f < FLAST)
  209.       f++;
  210.     else
  211.       f = FFIRST;
  212. #ifndef SEENBY
  213.     if (f == 9) f++;
  214. #endif
  215. #ifndef TEARLINE
  216.     if (f == 10) f++;
  217. #endif
  218.     break;
  219.  
  220.       case ENTER :
  221.     if (!checkname(tname)) {
  222.       f = 1;
  223.       break;
  224.     } /* if */
  225.  
  226. #ifdef SEENBY
  227.     seenbys = tseen;
  228. #endif
  229. #ifdef TEARLINE
  230.     tearline = ttear;
  231. #endif
  232.     arealist[area].softcr = tcr;
  233.     confirmations = tconfirm;
  234.     shownotes = tshow;
  235.     beepson = tbeep;
  236.     ptrfree(username);
  237.     ptrfree(fidolist);
  238.     ptrfree(userlist);
  239.     ptrfree(quotestr);
  240.     ptrfree(origin);
  241.     origin = torg;
  242.     username = tname;
  243.     fidolist = tlist1;
  244.     userlist = tlist2;
  245.     quotestr = tqs;
  246.     thisnode[CurAKA] = parsenode(taddr);
  247.     tabsize = ttab;
  248.     arealist[area].msgbits.is_priv = tpriv;
  249.     arealist[area].msgbits.is_crash = tcrash;
  250.     arealist[area].msgbits.is_kill = tkill;
  251.     globsrch = tsrch;
  252.     rm = trm;
  253.     usernum = tusernum;
  254.     if (!openmsgbase())
  255.       fatal("Could not open message base");
  256.     return;
  257.  
  258.       case SPACE:
  259.     set_color(co_normal);
  260.  
  261.     switch (f) {
  262.       case 1 : strcpy(tmp,tname);
  263.            gotoxy(OFFSET,PILINE + 1);
  264.            if (bgets(tmp,ILEN) != ABORT) {
  265.              ptrfree(tname);
  266.              tname = strdup(tmp);
  267.            }
  268.            break;
  269.       case 2 : gotoxy(OFFSET,PILINE + 2);
  270.            (void)bgets(taddr,ILEN);
  271.            break;
  272.       case 3 : strcpy(tmp,tlist1);
  273.            gotoxy(OFFSET,STLINE + 1);
  274.            if (bgets(tmp,ILEN) != ABORT) {
  275.              ptrfree(tlist1);
  276.              tlist1 = strdup(tmp);
  277.            }
  278.            break;
  279.       case 4 : strcpy(tmp,tlist2);
  280.            gotoxy(OFFSET,STLINE + 2);
  281.            if (bgets(tmp,ILEN) != ABORT) {
  282.              ptrfree(tlist2);
  283.              tlist2 = strdup(tmp);
  284.            }
  285.            break;
  286.       case 5 : strcpy(tmp,tqs);
  287.            gotoxy(OFFSET,STLINE + 3);
  288.            if (bgets(tmp,ILEN) != ABORT) {
  289.              ptrfree(tqs);
  290.              tqs = strdup(tmp);
  291.            }
  292.            break;
  293.       case 6 : strcpy(tmp,torg);
  294.            gotoxy(OFFSET-ORGOFS,STLINE + 4);
  295.            if (bgets(tmp,ILEN+ORGOFS) != ABORT) {
  296.              ptrfree(torg);
  297.              override = TRUE;
  298.              torg = strdup(tmp);
  299.            }
  300.            break;
  301.       case 7 : gotoxy(OFFSET,NULINE + 1);
  302.            ttab = getnum(1,trm,ttab);
  303.            break;
  304.       case 8 : gotoxy(OFFSET,NULINE + 2);
  305.            trm = getnum(1,maxx,trm);
  306.            break;
  307. #ifdef SEENBY
  308.       case 9 : tseen   = !tseen; break;
  309. #endif
  310. #ifdef TEARLINE
  311.       case 10: ttear   = !ttear; break;
  312. #endif
  313.       case 11: tcr     = !tcr; break;
  314.       case 12: tconfirm= !tconfirm; break;
  315.       case 13: tshow   = !tshow; break;
  316.       case 14: tbeep   = !tbeep; break;
  317.       case 15: tpriv   = !tpriv; break;
  318.       case 16: tkill   = !tkill; break;
  319.       case 17: tcrash  = !tcrash; break;
  320.       case 18: tsrch = !tsrch;  break;
  321.         } /* switch */
  322.     set_color(co_info);
  323.     break;
  324.  
  325.       default :
  326.     switch (tolower(ch & 0xff)) {
  327.       case 'n' : f = 1; break;
  328.       case 'a' : f = 2; break;
  329.       case 'p' : f = 3; break;
  330.       case 's' : f = 4; break;
  331.       case 'q' : f = 5; break;
  332.       case 'o' : f = 6; break;
  333.       case 't' : f = 7; break;
  334.       case 'r' : f = 8; break;
  335. #ifdef SEENBY
  336.       case 'b' : f = 9; tseen   = !tseen; break;
  337. #endif
  338. #ifdef TEARLINE
  339.       case 'l' : f = 10; ttear   = !ttear; break;
  340. #endif
  341.       case 'c' : f = 11; tcr     = !tcr; break;
  342.       case 'd' : f = 12; tconfirm= !tconfirm; break;
  343.       case 'h' : f = 13; tshow   = !tshow; break;
  344.       case 'w' : f = 14; tbeep   = !tbeep; break;
  345.       case 'v' : f = 15; tpriv   = !tpriv; break;
  346.       case 'i' : f = 16; tkill   = !tkill; break;
  347.       case 'k' : f = 17; tcrash  = !tcrash; break;
  348.       case 'g' : f = 18; tsrch = !tsrch;  break;
  349.         } /* switch */
  350.     break;
  351.     } /* switch */
  352.   } /* while */
  353.  
  354.   ptrfree(tname);
  355.   ptrfree(tlist1);
  356.   ptrfree(tlist2);
  357.   ptrfree(tqs);
  358.  
  359.   if (!openmsgbase())
  360.     fatal("Could not open message base");
  361. } /* settings */
  362.  
  363. static void update(int f)
  364. {
  365.   int color = get_color();
  366.  
  367.   switch (f) {
  368.     case 1 : gotoxy(10,PILINE + 1); set_color(co_hilite); bputc('N'); set_color(color); bputs("ame:"); gotoxy(OFFSET,PILINE + 1); bputs(tname);  break;
  369.     case 2 : gotoxy(10,PILINE + 2); set_color(co_hilite); bputc('A'); set_color(color); bputs("ddress:"); gotoxy(OFFSET,PILINE + 2); bputs(taddr);                            break;
  370.     case 3 : gotoxy(10,STLINE + 1); bputs("Userlist ("); set_color(co_hilite); bputc('P'); set_color(color); bputs("rimary):"); gotoxy(OFFSET,STLINE + 1); bputs(tlist1);     break;
  371.     case 4 : gotoxy(10,STLINE + 2); bputs("         ("); set_color(co_hilite); bputc('S'); set_color(color); bputs("econdary):"); gotoxy(OFFSET,STLINE + 2); bputs(tlist2);   break;
  372.     case 5 : gotoxy(10,STLINE + 3); set_color(co_hilite); bputc('Q'); set_color(color); bputs("uote String:"); gotoxy(OFFSET,STLINE + 3); bputs(tqs);                         break;
  373.     case 6 : gotoxy(10,STLINE + 4); set_color(co_hilite); bputc('O'); set_color(color); bputs("rigin:"); gotoxy(OFFSET-ORGOFS,STLINE + 4); bputs(torg);                              break;
  374.     case 7 : gotoxy(10,NULINE + 1); set_color(co_hilite); bputc('T'); set_color(color); bputs("ab setting:"); gotoxy(OFFSET,NULINE + 1); bprintf("%d",ttab);                  break;
  375.     case 8 : gotoxy(10,NULINE + 2); set_color(co_hilite); bputc('R'); set_color(color); bputs("ight margin:"); gotoxy(OFFSET,NULINE + 2); bprintf("%d",trm);                  break;
  376. #ifdef SEENBY
  377.     case 9 : gotoxy(10,SWLINE + 1); bputs("Seen-"); set_color(co_hilite); bputc('B'); set_color(color); bprintf("ys:        %s",(tseen   ) ? "Yes" : "No ");                  break;
  378. #endif
  379. #ifdef TEARLINE
  380.     case 10: gotoxy(OFFSET,SWLINE + 1); bputs("Tear"); set_color(co_hilite); bputc('l'); set_color(color); bprintf("ines:          %s",(ttear   ) ? "Yes" : "No ");   break;
  381. #endif
  382.     case 11: gotoxy(10,SWLINE + 2); bputs("Soft "); set_color(co_hilite); bputc('C'); set_color(color); bprintf("Rs:        %s",(tcr     ) ? "Yes" : "No ");          break;
  383.     case 12: gotoxy(OFFSET,SWLINE + 2); bputs("Confirm "); set_color(co_hilite); bputc('D'); set_color(color); bprintf("eletes:    %s",(tconfirm) ? "Yes" : "No ");   break;
  384.     case 13: gotoxy(10,SWLINE + 3); set_color(co_hilite); bputc('H'); set_color(color); bprintf("idden Lines:    %s",(tshow   ) ? "Yes" : "No "); break;
  385.     case 14: gotoxy(OFFSET,SWLINE + 3); set_color(co_hilite); bputc('W'); set_color(color); bprintf("arning beeps:      %s",(tbeep) ? "Yes" : "No "); break;
  386.     case 15: gotoxy(10,SWLINE + 4); bputs("Pri"); set_color(co_hilite); bputc('v'); set_color(color); bprintf("ileged:      %s",(tpriv) ? "On " : "Off"); break;
  387.     case 16: gotoxy(OFFSET,SWLINE + 4); bputc('K'); set_color(co_hilite); bputc('i'); set_color(color); bprintf("ll/Sent:          %s",(tkill) ? "On " : "Off"); break;
  388.     case 17: gotoxy(10,SWLINE + 5); set_color(co_hilite); bputc('K'); set_color(color); bprintf("rash:           %s",(tcrash) ? "On " : "Off"); break;
  389.     case 18: gotoxy(OFFSET,SWLINE + 5); set_color(co_hilite); bputc('G'); set_color(color); bprintf("lobal Search:      %s",(tsrch) ? "On " : "Off"); break;
  390.   } /* switch */
  391.  
  392.   set_color(color);
  393. } /* update */
  394.  
  395. static BOOLEAN checkname(char *n)
  396. {
  397.   int i;
  398.  
  399.   if (!useusersbbs) {        /* doesn't use USERS.BBS? */
  400.     if (*n == EOS)        /* empty? */
  401.       i = -1;
  402.     else
  403.       i = 0;
  404.   } else {
  405.     i = searchuser(n,FALSE);
  406.   } /* else */
  407.  
  408.   if (i < 0) {
  409.     gotoxy(1,22);
  410.     bputs("________________________________________________________________________________");
  411.     gotoxy(2,22);
  412.     set_color(co_warn);
  413.     bprintf(" User '%s' not found in user base ", n);
  414.     set_color(co_normal);
  415.     tusernum = 0;
  416.     return FALSE;
  417.   } else {
  418.     tusernum = i;
  419.     return TRUE;
  420.   } /* else */
  421. } /* checkname */
  422.  
  423. #endif
  424.